Drag’n’Drop-Framwork ALV-Grid
Heute bin ich beim Surfen im SAP-System über die Klasse CL_ALV_DD_LISTBOX gestolpert. Dolle Sache:
Einfach zwei Datentabellen definieren, zwei Grids erzeugen, der Instanz von cl_alv_dd_double_listbox übergeben und die zwei Funktionscodes zum Bewegen der Einträge definieren. Aufrufen und am Ende hat man in seinen zwei Datentabellen die vom Anwender definierten Einträge.
Die Anregung stammt aus dem Report RSPLS_ENQUEUE_INFO.
Coding
DATA gr_dd TYPE REF TO cl_alv_dd_double_listbox. DATA gr_grid_s TYPE REF TO cl_alv_dd_listbox. "source DATA gr_grid_t TYPE REF TO cl_alv_dd_listbox. "target DATA gr_cont_s TYPE REF TO cl_gui_custom_container. "source DATA gr_cont_t TYPE REF TO cl_gui_custom_container. "target DATA gs_layo_s TYPE lvc_s_layo. DATA gs_layo_t TYPE lvc_s_layo. DATA gt_fcat TYPE lvc_t_fcat. DATA gt_sort TYPE lvc_t_sort. DATA gt_data_s TYPE STANDARD TABLE OF t006a. DATA gt_data_t TYPE STANDARD TABLE OF t006a. START-OF-SELECTION. PERFORM init. CALL SCREEN 100. *----------------------------------------------------------------------* * MODULE pbo OUTPUT *----------------------------------------------------------------------* MODULE pbo OUTPUT. SET PF-STATUS 'DD_GRID'. PERFORM prepare_grid USING gr_grid_s gr_cont_s 'CONT_SOURCE' gs_layo_s gt_data_s. PERFORM prepare_grid USING gr_grid_t gr_cont_t 'CONT_TARGET' gs_layo_t gt_data_t. IF gr_dd IS INITIAL. CREATE OBJECT gr_dd EXPORTING i_grid1 = gr_grid_s i_grid2 = gr_grid_t. ENDIF. ENDMODULE. "pbo OUTPUT *----------------------------------------------------------------------* * MODULE pai INPUT *----------------------------------------------------------------------* MODULE pai INPUT. CASE sy-ucomm. WHEN 'BACK'. SET SCREEN 0. LEAVE SCREEN. WHEN 'MOVE_TO_TARGET'. CALL METHOD gr_dd->movetogrid2 EXPORTING i_ok_code = sy-ucomm. WHEN 'MOVE_TO_SOURCE'. CALL METHOD gr_dd->movetogrid1 EXPORTING i_ok_code = sy-ucomm. ENDCASE. * IF NOT gr_dd IS INITIAL. * CALL METHOD gr_dd->set_grids_state( abap_true ). "X = display/ space = edit * ENDIF. ENDMODULE. "pai INPUT *&---------------------------------------------------------------------* *& Form prepare_grid *&---------------------------------------------------------------------* FORM prepare_grid USING grid TYPE REF TO cl_alv_dd_listbox cont TYPE REF TO cl_gui_custom_container name TYPE clike layo TYPE lvc_s_layo data TYPE STANDARD TABLE. IF cont IS INITIAL. *== create container CREATE OBJECT cont EXPORTING container_name = name. ENDIF. IF grid IS INITIAL. *== create grid CREATE OBJECT grid EXPORTING i_parent = cont i_grid_style = 1. *== set grid CALL METHOD grid->set_table_for_first_display EXPORTING is_layout = layo CHANGING it_outtab = data it_fieldcatalog = gt_fcat it_sort = gt_sort. ELSE. *== refresh CALL METHOD grid->set_frontend_fieldcatalog EXPORTING it_fieldcatalog = gt_fcat. CALL METHOD grid->set_frontend_layout EXPORTING is_layout = gs_layo_s. CALL METHOD grid->refresh_table_display. ENDIF. ENDFORM. "prepare_grid *&---------------------------------------------------------------------* *& Form init *&---------------------------------------------------------------------* FORM init. *== local data FIELD-SYMBOLS LIKE LINE OF gt_fcat. *== get source data SELECT * FROM t006a INTO TABLE gt_data_s UP TO 20 ROWS WHERE spras = sy-langu. *== set title for source: gs_layo_s-grid_title = text-003. gs_layo_s-smalltitle = 'X'. gs_layo_s-cwidth_opt = 'X'. gs_layo_s-sel_mode = 'A'. *== set title for target: gs_layo_t-grid_title = text-004. gs_layo_t-smalltitle = 'X'. gs_layo_t-cwidth_opt = 'X'. gs_layo_t-sel_mode = 'A'. *== get fieldcatalog CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'T006A' i_client_never_display = 'X' CHANGING ct_fieldcat = gt_fcat EXCEPTIONS OTHERS = 3. *== display only unit and text LOOP AT gt_fcat ASSIGNING . CASE -fieldname. WHEN 'MSEHI' OR 'MSEH3' OR 'MSEH6'. -tech = abap_true. ENDCASE. ENDLOOP. ENDFORM. "init
Dynpro
Ablauflogik
PROCESS BEFORE OUTPUT.
MODULE pbo.
*
PROCESS AFTER INPUT.
MODULE pai.
GUI-Status
[notice type = ‘info’]Leider haben die Klassen eine kleine Macken. Sobald die ersten Einträge per Funktionstasten verschoben wurden, erscheint die Markierspalte und es ist kein Drag-and-Drop mehr möglich… :([/notice]
- 7. December: Excel Racing Simulation – Root Vole Race - 7. Dezember 2024
- 5. December: ABAPConf - 5. Dezember 2024
- 4. December: Only a lazy developer is a good developer - 4. Dezember 2024